import request from "@/utils/request";
import { userUrl, url } from "./url";

export async function addData(params) {
  // console.log(params, "新增操作参数");
  return request({
    url: `${userUrl}/role/add`,
    method: "POST",
    data: params,
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}

export async function editData(params) {
  // console.log(params, "修改操作参数");
  return request({
    url: `${userUrl}/role/edit`,
    method: "PUT",
    data: params,
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}
//删除
export async function deleteData(params) {
  // console.log(params, "删除操作参数");
  let id = params.id === "delete" ? "id" : "ids";
  return request({
    url: `${userUrl}/role/${params.id}?${id}=${params.deleteId}`,
    method: "DELETE",
  });
  /*  return {
    success: true,
    message: "删除成功!",
    code: 200,
    result: "删除成功!",
    timestamp: 1720688633000,
  };*/
}

export async function getTableBody(params) {
  // console.log(params, "查询参数");

  return request({
    url: `${userUrl}/role/list`,
    method: "GET",
    params: params,
  });
  /* return {
    success: true,
    message: "",
    code: 0,
    result: {
      records: [
        {
          id: "1169504891467464705",
          roleName: "第三方登录角色",
          roleCode: "third_role",
          description: "第三方登录角色",
          createBy: "admin",
          createTime: "2019-09-05 14:57:49",
          updateBy: "admin",
          updateTime: "2020-05-02 18:20:58",
          tenantId: 0,
          topRole: [{ label: "开发人员", value: "developAdmin" }],
        },
        {
          id: "1260924539346472962",
          roleName: "财务出纳",
          roleCode: "caiwu",
          description: null,
          createBy: "admin",
          createTime: "2020-05-14 21:26:52",
          updateBy: null,
          updateTime: null,
          tenantId: 0,
          topRole: [{ label: "系统管理员", value: "adminAi" }],
        },
      ],
      total: 11,
      size: 50,
      current: 1,
      orders: [],
      optimizeCountSql: true,
      searchCount: true,
      maxLimit: null,
      countId: null,
      pages: 1,
    },
    timestamp: 1722418661335,
  };*/
}
//角色授权
export async function getRoleToAuth(id) {
  return request({
    url: `${userUrl}/permission/saveRolePermission`,
    method: "POST",
    data: {
      roleId: id,
      permissionIds:
        "1170592628746878978,1170592628746878978,119213522910765570,1214376304951664642,1214376304951664642,1214462306546319362,1214462306546319362,1280350452934307841,1438108176273760258,1438108176273760258,1438108176814825473,1438108176814825473,1438108178911977473,1438108183395688450,1438108183492157442,1438108183630569474,1438108183630569477,1438108183907393538,1438108184049999873,1438108186717577217,1438108187103453186,1438108187455774722,1438108187678072833,1438108187871010818,1438108188034588674,1438108188378521602,1438108188378521602,1438108188542099458,1438108188714065922,1438108189062193153,1438108189427097601,1438108189754253313,1438108190110769154,1438108190404370433,1438108190777663490,1438108191356477442,1438108192623157249,1438108192623157249,1438108193701093378,1438108193701093378,1438108194992939010,1438108195307511809,1438108195487866881,1438108195638861825,1438108195924074497,1438108196263813121,1438108196528054273,1438108196855209985,1438108220418809857,1438108220523667458,1438108220724994049,1438108220896960513,1438108221127647234,1438108221270253570,1438108225451974658,1438115924159881218,1438116003012796418,1438469604861403137,1438469604861403137,1438782530717495298,1438782530717495298,1438782641187074050,1438782641187074050,1438782851980210178,1438782851980210178,1455735714507472898,1455735714507472898,1588513553652436993,1588513553652436993,1592112984361365505,1592112984361365505,1592113148350263298,1592113148350263298,1592114574275211265,1592114574275211265,1592114652566089729,1592114652566089729,1592114721138765826,1592114721138765826,1592114772665790465,1592114772665790465,1592114823467200514,1592114823467200514,1592114893302362114,1592114893302362114,1592114955650691074,1592114955650691074,1592115070432014338,1592115070432014338,1592115115361398786,1592115115361398786,1592115162379546625,1592115162379546625,1592115213910765570,1592115213910765570,1592115712466710529,1592115712466710529,1592115914493751297,1592115914493751297,1592116663936184322,1592116663936184322,1592117222764277761,1592117222764277761,1592117276539449345,1592117276539449345,1592117377299214337,1592117377299214337,1592117422006300673,1592117422006300673,1592117625664925697,1592117625664925697,1592117748209905665,1592117748209905665,1592117804359053314,1592117804359053314,1592117990305132545,1592117990305132545,1592118053634928641,1592118053634928641,1592118192218927105,1592118192218927105,1592118254844080130,1592118254844080130,1592118306983473154,1592118306983473154,1592118356778250241,1592118356778250241,1592118414990995457,1592118414990995457,1592118604640645122,1592118604640645122,1592118648315932674,1592118648315932674,1592119001883176961,1592119001883176961,1592120052866707457,1592120052866707457,1592120222727630849,1592120222727630849,1592120224120850434,1592120224120850434,1592120224120850434,1592120323667750914,1592120323667750914,1592120372296511490,1592120372296511490,1592120427007012865,1592120427007012865,1592120484120850434,1592120484120850434,1592120594695286785,1592120594695286785,1592120649007329281,1592120649007329281,1592135223910765570,1592135223910765570,1593160905216663554,1593160905216663554,1593160959633563650,1593160959633563650,1593161025790320641,1593161025790320641,1593161089787011074,1593161089787011074,1593185714482880514,1593185714482880514,1596141938193747970,1596141938193747970,1596335805278990338,1596335805278990338,1597419994965786625,15c92115213910765570,15c92115213910765570,1600105607009165314,1600108123037917186,1600129606082650113,1609123240547344385,1609123437247619074,1609164542165012482,1609164635442139138,1611620416187969538,1611620600003342337,1611620654621569026,1611620772498218641,1611620772498288641,1611650772498288641,1612438989792034818,1613620712498288641,1620261087828418562,1620305415648989186,1620327825894981634,1621620772498288641,1629109281748291586,1629109281748291586,1661572802889007106,1663816667704500225,1668174661456171010,1674708136602542082,1693195557097164801,1693195557097164801,1697220712498288641,1701575168519839746,1701575168519839746,190c2b43bec6a5f7a4194a85db67d96a,190c2b43bec6a5f7a4194a85db67d96a,1a0811914300741f4e11838ff37a1d3a,1a0811914300741f4e11838ff37a1d3a,1d592115213910765570,1d592115213910765570,3f915b2769fc80648e92d04e84ca059d,3f915b2769fc80648e92d04e84ca059d,45c966826eeff4c99b8f8ebfe74511fc,45c966826eeff4c99b8f8ebfe74511fc,5c2f42277948043026b7a14692456828,5c2f42277948043026b7a14692456828,718c961cd9c54ee49769895e4a46fb8c,910fe52f6e73416d84f28250a5dba8f2,9502685863ab87f0ad1134142788a385,9502685863ab87f0ad1134142788a385,97bd42b258a4488c8a7480d733d7687b,98cec6ad57cf408bad0953dc0a365f01,cd1117b1dd4a4211972cb7baa3e8e935,d7d6e2e4e2934f2c9385a623fd98c6f3,d7d6e2e4e2934f2c9385a623fd98c6f3,f85171e8de60482db611598010b18184",
    },
  });

  /*  return {
    success: true,
    message: "",
    code: 200,
    result: "",
    timestamp: 1722394371523,
  };*/
}
//维度授权
export async function roleColumnAuth1(id) {
  console.log("维度授权");
  return request({
    url: `${url}/roleColumnAuth/${id}/4028808690ac98930190aca1ed8c0005`,
    method: "POST",
    data: {
      authMode: "role",
      authId: [
        "1812147624828006401",
        "1812147624861560833",
        "1812147624878338049",
        "1812147626686083074",
        "1812147626715443201",
        "1812147626736414722",
        "1812147634411991041",
        "1812147634453934081",
        "1812147634470711298",
        "1812147638992171010",
        "1812147639021531138",
        "1812147639038308354",
        "1812147644583178241",
        "1812147644612538370",
        "1812147644629315585",
        "1812147649238855682",
        "1812147649268215810",
        "1812147649284993026",
        "1812147655219933185",
        "1812147655249293314",
        "1812147655270264834",
        "1812147660508950529",
        "1812147660538310657",
        "1812147660555087874",
        "1812147666641022978",
        "1812147666670383106",
        "1812147666687160321",
        "1812147681291726850",
        "1812147684454232066",
        "1812147688652730369",
        "1812147678791921665",
      ],
    },
  });
}
//维值授权
export async function roleColumnAuth2(id) {
  return request({
    url: `${url}/roleColumnAuth/${id}/4028808690ac98930190aca1f5c80006`,
    method: "POST",
    data: {
      authMode: "role",
      authId: [
        "1812148411289366530",
        "1812148411318726657",
        "1812148411339698178",
        "1812148414208602114",
        "1812148414237962241",
        "1812148414254739457",
        "1812148418071556097",
        "1812148418100916225",
        "1812148418121887746",
        "1812148422236499970",
        "1812148422265860098",
        "1812148422282637313",
        "1812148426057510914",
        "1812148426086871041",
        "1812148426103648258",
        "1812148428783808514",
        "1812148428813168641",
        "1812148428834140162",
        "1812148431589797889",
        "1812148431619158017",
        "1812148431635935233",
        "1812148443895885826",
        "1812148445959483394",
        "1812148448920662017",
        "1812148452938805249",
      ],
    },
  });
}
//基础指标授权
export async function roleColumnAuth3(id) {
  return request({
    url: `${url}/roleColumnAuth/${id}/4028808690ac98930190aca1e5930004`,
    method: "POST",
    data: {
      authMode: "role",
      authId: [
        "1812148889570045953",
        "1812148889603600385",
        "1812148889620377602",
        "1812148893986648066",
        "1812148894016008194",
        "1812148894032785409",
        "1812148897149153282",
        "1812148897178513410",
        "1812148897195290626",
        "1812148899401494530",
        "1812148899435048962",
        "1812148899451826178",
        "1812148902031323137",
        "1812148902060683266",
        "1812148902077460482",
        "1812148904568877058",
        "1812148904598237185",
        "1812148904619208705",
        "1812148907555221505",
        "1812148907588775937",
        "1812148907605553153",
        "1812148920553369601",
        "1812148923007037441",
        "1812148925611700226",
        "1812148928551907330",
      ],
    },
  });
}
//角色授权
export async function getRoleAuthList(params) {
  // console.log(params, "获取已有权限的list操作参数");
  return request({
    url: `${userUrl}/permission/queryRolePermission`,
    method: "GET",
    params: params,
  });

  /*  return {
    success: true,
    message: "",
    code: 0,
    result: ["userManage", "userManage:add", "roleManage:edit"],
    timestamp: 1722482821496,
  };*/
}
//校验角色编码
export async function checkRoleCode(params) {
  // console.log(params, "角色名称校验操作参数");
  return request({
    url: `${userUrl}/role/checkRoleCode`,
    method: "GET",
    params: params,
    mark: true,
  });

  /*  return {
    success: true,
    message: "该值不可用，系统中已存在！",
    code: 0,
    result: true,
    timestamp: 1721698656796,
  };*/
}
//根据角色id获取角色权限
export async function getAuth(params) {
  return request({
    url: `${userUrl}/dataPermissions/queryTreeList`,
    method: "GET",
    params: params,
  });
  /*  let result = [
    [
      {
        label: "维度管理",
        value: "dimensionManagement",
      },
      {
        label: "新增",
        value: "dimensionManagement:add",
      },
      {
        label: "删除",
        value: "dimensionManagement:delete",
      },
    ],
    [
      {
        label: "用户管理",
        value: "userManage",
      },
      {
        label: "新增",
        value: "userManage:add",
      },
      {
        label: "修改",
        value: "userManage:edit",
      },
      {
        label: "新增",
        value: "userManage:delete",
      },
    ],
    [
      {
        label: "新增",
        value: "roleManage:add",
      },
      {
        label: "修改",
        value: "roleManage:edit",
      },
      {
        label: "新增",
        value: "roleManage:delete",
      },
    ],
  ];
  result = result.map((item) => JSON.stringify(item));
  return {
    success: false,
    message: "该值不可用，系统中已存在！",
    code: 200,
    result: result,
    timestamp: 1721698656796,
  };*/
}
//新增修改角色权限
export async function insertTreeList(params) {
  return request({
    url: `${userUrl}/dataPermissions/insertTreeList`,
    method: "POST",
    data: params,
  });
  /*  return {
      code:200
    }*/
}
